<?php 
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$status=$_GPC['status'];
load()->func('tpl');
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
$where=" WHERE a.uniacid=:uniacid";
if(isset($_GPC['keywords'])){
    $where.="  and (a.teacher_name LIKE  concat('%', :name,'%') or b.cate_name LIKE  concat('%', :name,'%'))";
    $data[':name']=$_GPC['keywords']; 
    $type='all';  
}
$data[':uniacid']=$_W['uniacid'];
$sql="SELECT a.*,b.cate_name FROM ".tablename('snx_teacher'). " a"  . " left join " . tablename("snx_school") . " b on a.school_id=b.id ".$where." ORDER BY a.create_time asc";
$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('snx_teacher'). " a"  . " left join " . tablename("snx_school") . " b on a.school_id=b.id ".$where." ORDER BY a.create_time asc",$data);
$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$list=pdo_fetchall($select_sql,$data);

// foreach ($list as $key => $value) {
// 	$row = pdo_fetchall("select a.class_name,b.name,c.course_name,d.cate_name from" .tablename('snx_class') ." a left join " .tablename('snx_course') ." b on a.cou_id=b.id left join" .tablename('snx_coursecate') ." c on b.c_id=c.id left join" .tablename('snx_school') . "d on c.school_id=d.id where a.id in({$value['class_id']}) and a.uniacid={$_W['uniacid']}");
// 	$list['class'] = $row;
// 	echo json_encode($list,320);
// }die;
$pager = pagination($total, $pageindex, $pagesize);
if($operation=='delete'){
  $res=pdo_delete('snx_teacher',array('id'=>$_GPC['id']));
  if($res){
    message('删除成功',$this->createWebUrl('teacher',array()),'success');
  }else{
    message('删除失败','','error');
  }
}
// if($_GPC['op']=='change'){
//    $res=pdo_update('snx_teacher',array('status'=>$_GPC['status']),array('id'=>$_GPC['id']));
//     if($res){
//         message('操作成功',$this->createWebUrl('teacher',array()),'success');
//     }else{
//         message('操作失败','','error');
//     }
// }
include $this->template('web/teacher');

 ?>